package com.heap.max;

import java.util.Random;

public class Test {
    public static void main(String[] args) {
        int n = 1000000;
        MaxHeap<Integer> maxHeap = new MaxHeap<>();
        Random random = new Random();
        for (int i = 0 ; i < n ; i ++) {
            maxHeap.add(random.nextInt(Integer.MAX_VALUE));
        }

        // 堆排序：每次都从堆中取出最大的元素相当于对堆进行从大到小排序
        int[] arr = new int[n];
        for (int i = 0 ; i < n ; i ++ ) {
            arr[i] = maxHeap.extractMax();
        }
        for (int i = 1 ; i < n ; i ++ ) {
            if (arr[i - 1] < arr[i]) {
                throw new IllegalArgumentException("Error");
            }
        }
        System.out.println("Testing passed!");
    }
}
